if(length(tryCatch(list.dirs(path="~/Library/CloudStorage/Dropbox/Robots and Trade in Services"),error=function(e) e))==0){
  base.path<-"~/Dropbox/Robots and Trade in Services/"
} else {
  base.path<-"~/Library/CloudStorage/Dropbox/Robots and Trade in Services/"
}

#Load data and functions
source(paste0(base.path,"Drafts/Replication/03 Functions and Processing.R"))

lucid.proc$policy_difference <- ifelse(lucid.proc$treatment_automation_labor=="Labor",lucid.proc$restrict_imports_difference,lucid.proc$restrict_automation_difference)

###########################
## Figure 7 (Appendix B) ##
###########################

p1<-plotter(subsample = "Labor",depvar="restrict_imports")+labs(title="Within Labor Treatment")
p2<-plotter(subsample = "Labor",depvar="benefits_to_unemployed")
p3<-plotter(subsample = "Automation",depvar="restrict_automation")+labs(title="Within Automation Treatment")
p4<-plotter(subsample = "Automation",depvar="benefits_to_unemployed")

#Code inspired by https://wilkelab.org/cowplot/articles/shared_legends.html

legend <- cowplot::get_legend(
  
  p1 + 
    guides(color = guide_legend(title="Treatment",nrow = 1)) +
    theme(legend.position = "bottom")
)

combined.plot<-cowplot::plot_grid(
  p1+coord_cartesian(xlim=c(30,70)),
  p3+coord_cartesian(xlim=c(30,70)),
  p2+coord_cartesian(xlim=c(30,70)),
  p4+coord_cartesian(xlim=c(30,70)),
  nrow=2,
  ncol=2
)

cowplot::plot_grid(combined.plot,legend,ncol=1,rel_heights = c(2,0.25))
